package com.zsinfo.guoss.supplier.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.zsinfo.guoss.supplier.utils.CommentUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * BaseFragment
 * hyk
 */
public abstract class BaseFragment extends Fragment {

    protected Context context;

    private Unbinder unbinder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(getContentLayoutRes(), container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        unbinder = ButterKnife.bind(this, view);
        initView(view);

    }


    public Context getFragmentContext() {
        return context;
    }

    /**
     * 获取fragment布局
     *
     * @return
     */
    protected abstract int getContentLayoutRes();


    /**
     * 初始化控件
     */
    protected abstract void initView(View view);


    public void MyDestroy() {

    }

    /**
     * 显示吐司
     *
     * @param text
     */
    protected void showToast(String text) {
        CommentUtil.showSingleToast(text);
    }

    /**
     * @param cls 要启动的activity
     */
    protected void startActivity(Class<?> cls) {
        CommentUtil.startActivity(context, cls);
    }

    @Override
    public void onDestroy() {
        if (unbinder != null) {
            unbinder.unbind();
        }
        MyDestroy();
        super.onDestroy();
    }
}
